package com.wigem.util;

import com.wigem.framework.common.pojo.Tree;
import com.wigem.framework.common.util.common.TreeUtils;

import java.util.ArrayList;
import java.util.List;

public class TreeUtil extends TreeUtils {
    public static List<Tree> getChildListById(List<Tree> dataList, String parentId) {
        return getChildListById(dataList, parentId, new ArrayList<>());
    }


    private static List<Tree> getChildListById(List<Tree> dataList, String parentId, List<Tree> resultList) {
        dataList.stream().filter(p -> parentId.equals(p.getId())).forEach((item) -> {
            resultList.add(item);
        });
        dataList.stream().filter(p -> parentId.equals(p.getParentId())).forEach((item) -> {
            resultList.add(item);
            getChildListById(dataList, item.getId(), resultList);
        });
        return resultList;
    }
}
